package cyce.dfs.fileChooser;

import java.util.*;

public class Directory extends File {

	private ArrayList<File> children;
	private boolean isRoot;
	
	public Directory(Directory parent, String directoryName) {
		super(parent, directoryName);
		this.children = new ArrayList<File>();
		isRoot = (parent == null);
	}
	
	public Directory addDirectory(String name) {
		Directory directory = new Directory(this, name);
		this.children.add(directory);
		return directory;
	}
	public File addFile(String name) {
		File file = new File(this, name);
		this.children.add(file);
		return file;
	}
	
	@Override
	public String list() {
		String list = this.getName() + "{";
		for (File file : this.children) {
			list +=  "\n" + file.list();
		}
		return list + "}";
	}
	
	public ArrayList<File> children() {
		return this.children;
	}

	@Override
	public File getChildAt(int index) {
		return this.children.get(index);
	}

	@Override
	public int getChildCount() {
		return this.children.size();
	}

	@Override
	public int getIndex(File file) {
		return this.children.indexOf(file);
	}
	
	@Override
	public boolean isLeaf() {
		return false;
	}
}
